package 代码随想录.链表;

import common.ListNode;

public class a206翻转链表 {
    static class Solution {
        public ListNode reverseList(ListNode head) {
            ListNode pre = null;
            while (head != null) {
                ListNode next = head.next;
                head.next = pre;
                pre = head;
                head = next;
            }
            return pre;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        ListNode read = ListNode.read(new Integer[]{1, 2, 3, 4, 5});
        ListNode listNode = solution.reverseList(read);
        ListNode.print(listNode);
    }
}
